﻿<Window x:Class="StackHash.ScriptManager"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vcs="clr-namespace:StackHash.ValueConverters"
    Title="Script Manager - StackHash" Height="450" MinHeight="450" Width="400" MinWidth="400" WindowStartupLocation="CenterOwner" Icon="/StackHash;component/StackHash.ico" ShowInTaskbar="False" Loaded="Window_Loaded" Closed="Window_Closed">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="MasterResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Window.CommandBindings>
        <CommandBinding Command="Help" x:Name="commandBindingHelp" Executed="commandBindingHelp_Executed" />
    </Window.CommandBindings>
    <Grid IsEnabled="{Binding NotBusy}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="10" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        
        <Rectangle Margin="10" Grid.ColumnSpan="2" Name="rectangleTestTip" Fill="LightYellow" Stroke="Black" Visibility="{Binding Path=CurrentCab, Converter={StaticResource nullNotCollapsedConverter}}" />
        <TextBlock Margin="10" Padding="6" Grid.ColumnSpan="2" Name="textBlockTestTip" TextWrapping="Wrap" Visibility="{Binding Path=CurrentCab, Converter={StaticResource nullNotCollapsedConverter}}">To enable testing Select a cab in the main window before opening Script Manager.</TextBlock>

        <ListView Margin="10" Grid.Row="1" ItemsSource="{Binding ScriptData}" SelectionMode="Single" Name="listViewScripts" MouseDoubleClick="listViewScripts_MouseDoubleClick" SelectionChanged="listViewScripts_SelectionChanged" GridViewColumnHeader.Click="listViewScriptsHeader_Click">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="_Add Script" Name="menuItemAdd" Click="menuItemAdd_Click" />
                    <MenuItem Header="_Edit Script" Name="menuItemEdit" Click="menuItemEdit_Click" />
                    <MenuItem Header="_Test Script" Name="menuItemTest" Click="menuItemTest_Click" />
                    <MenuItem Header="_Delete Script" Name="menuItemDelete" Click="menuItemDelete_Click" />
                </ContextMenu>
            </ListView.ContextMenu>
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="100">
                        <GridViewColumnHeader Tag="Name" Content="Script Name" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Name}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="75">
                        <GridViewColumnHeader Tag="IsReadOnly" Content="System" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding IsReadOnly, Converter={StaticResource boolToYesNoConverter}}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="75">
                        <GridViewColumnHeader Tag="RunAutomatically " Content="Automatic" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding RunAutomatically , Converter={StaticResource boolToYesNoConverter}}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="125">
                        <GridViewColumnHeader Tag="DumpType " Content="Run On" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DumpType, Converter={StaticResource dumpTypeDisplayConverter}}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="125">
                        <GridViewColumnHeader Tag="LastModifiedDate " Content="Last Modified" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding LastModifiedDate, Converter={StaticResource dateTimeDisplayConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="125">
                        <GridViewColumnHeader Tag="CreationDate " Content="Created" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding CreationDate, Converter={StaticResource dateTimeDisplayConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        
        <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Vertical" VerticalAlignment="Top" Margin="7">
            <Button Margin="3" Name="buttonAdd" Click="buttonAdd_Click">_Add</Button>
            <Button Margin="3" Name="buttonEdit" Click="buttonEdit_Click">_Edit</Button>
            <Button Margin="3" Name="buttonTest" Click="buttonTest_Click">_Test</Button>
            <Button Margin="3" Name="buttonDelete" Click="buttonDelete_Click">_Delete</Button>
        </StackPanel>

        <Border Grid.Row="3" Grid.ColumnSpan="2" Style="{StaticResource ButtonBorder}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <Button Margin="10" Command="Help">_Help</Button>
                
                <Button IsDefault="True" Margin="10" Grid.Column="1" HorizontalAlignment="Right" Name="buttonClose" Click="buttonClose_Click">_Close</Button>
            </Grid>
        </Border>
    </Grid>
</Window>
